package bat.ke.qq.com.sql;


import bat.ke.qq.com.pojo.Blog;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;

/***
 * sql 演示
 */
public class SqlTestMain {
  public static void main(String[] args) throws IOException {
    String resource = "mybatis-config.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    SqlSession session = sqlSessionFactory.openSession();
    HashMap<Object, Object> hashMap = new HashMap<>();
    //hashMap.put("id", 101);
    hashMap.put("username", "Monkey");
    List<Blog> all = session.selectList("org.mybatis.example.BlogMapper.sqlBlog", hashMap);
    for (Blog blog : all) {
      System.out.println(blog);
    }
  }
}
